package com.data.basic.chapter03;

import java.util.Stack;

/**
 * 符号匹配的问题
 * Created by wangbing on 2018/5/1.
 */
public class Solution {
    public boolean isValid(String s) {
        Stack<Character> statck = new Stack<Character>();
        for (int i = 0;i<s.length();i++){
            char c = s.charAt(i);
            if (c=='('||c=='['||c=='{'){
                statck.push(c);
            }else{
                if (statck.isEmpty()){
                    return false;
                }
                char  topChar = statck.peek();
                if (c=='('&&topChar!=')'){
                    return false;
                }if (c=='['&&topChar!=']'){
                    return false;
                }if (c=='{'&&topChar!='}'){
                    return false;
                }
                statck.pop();


            }
        }
        return statck.isEmpty();
    }
}
